<template>
    <a-card :bordered="false">
        <!-- table区域-begin -->
        <div class="table-page-search-wrapper">
            <h2 class="text-center  margin-bottom">{{title}}</h2>
        </div>
        <div>
            <a-table
                    ref="table"
                    size="middle"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="false"
                    class="j-table-force-nowrap"
            >
                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <img v-else :src="text" height="25px" alt style="width: auto;height: 50px;"/>
                </template>

                <span slot="action" slot-scope="text, record">
                    <span v-has="'customer:suspension:of:business:apply'" >
                        <a style="color: #c72121;"
                           v-if="record.operationState == 0"
                           @click="toPage(record,'apply0')">暂停营业申请</a>
                        <a  style="color: orange;"
                           v-if="record.operationState == 1"
                           @click="toPage(record,'apply1')">恢复营业申请</a>
                    </span>
                    <a-divider v-has="'law:enforcement:qrcode'" v-if="record.isContract === 1" type="vertical"/>
                    <span v-has="'law:enforcement:qrcode'" v-if="record.isContract === 1">
                        <a  style="color: limegreen;"
                           @click="toPrintEnforcePage(record)">执法凭证</a>
                    </span>


                </span>
            </a-table>
        </div>
        <!--  打印执法凭证v2 -->
        <print-customer-data-v2 ref="printRefV2"></print-customer-data-v2>
    </a-card>
</template>

<script>
    /**
     * create by Jane
     * 机构台账信息
     */
    import '@/assets/less/TableExpand.less'
    import { mixinDevice } from '@/utils/mixin'
    import SelectArea from '@/components/Jane/SelectArea'
    import PrintCustomerDataV2 from '@jyb_v3/customer/modules/PrintCustomerDataV2'
    import * as user from '../../../api/user'

    export default {
        mixins: [mixinDevice],
        components: {
            SelectArea,
            PrintCustomerDataV2
        },
        data() {
            return {
                title: '我的机构信息列表',
                /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
                queryParam: {},
                /* 数据源 */
                dataSource: [],
                // 表头
                columns: []
            }
        },
        mounted() {
            this.initDictConfig()
        },
        methods: {
            async initDictConfig() {
                await this.setColumns()
                await this.getDataSource()
            },
            getDataSource: async function() {
                let res = await user.getAllCustomerByUserId()
                if (res) {
                    this.dataSource = res || []
                }
            },

            // 打印执法凭证
            toPrintEnforcePage:function(row){
                let ref = this.$refs.printRefV2
                if (ref) {
                    ref.creatQrCode(row)
                }
            },
            // 设置表格头部信息
            setColumns() {
                this.columns = [
                    {
                        title: '序号',
                        dataIndex: 'id',
                        key: 'rowIndex',
                        width: 60,
                        align: 'center',
                        scopedSlots: { customRender: 'htmlSlot' },
                        customRender: (text, row, index) => {
                            return parseInt(index) + 1
                        }
                    },
                    {
                        title: '机构名称',
                        align: 'center',
                        dataIndex: 'customerName',
                        key: 'customerName'
                    },
                    {
                        title: '机构编号',
                        align: 'center',
                        dataIndex: 'customerNumber',
                        key: 'customerNumber'
                    },
                    {
                        title: '负责人',
                        align: 'center',
                        dataIndex: 'leadername',
                        key: 'leadername'
                    },
                    {
                        title: '负责人电话',
                        align: 'center',
                        dataIndex: 'leaderphone',
                        key: 'leaderphone'
                    },
                    {
                        title: '机构地址',
                        align: 'center',
                        dataIndex: 'address',
                        key: 'address'
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: 'center',
                        width: 147,
                        scopedSlots: { customRender: 'action' }
                    }
                ]
            },
            searchQuery: function() {
                this.getDataSource(1)
            },
            toPage(item,type){
                if(type == 'apply0'){
                    item['applyType'] = 0;
                    this.$router.push({
                        path: '/jyb_v3/customer/CustomerBusinessApplyForm',
                        query: item
                    });
                }
                if(type == 'apply1'){
                    item['applyType'] = 1;
                    this.$router.push({
                        path: '/jyb_v3/customer/CustomerBusinessApplyForm',
                        query: item
                    });
                }
            }
        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less';
</style>
